package cn.sibu.tuchapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.TextView;

public class RemoteScrollActivity extends AppCompatActivity  implements View.OnTouchListener{


    private TextView mTouchText;
    private HorizontalScrollView mScrollView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remote_scroll);

        mTouchText = (TextView) findViewById(R.id.text_touch);
        mScrollView = (HorizontalScrollView) findViewById(R.id.scroll_view);
        //为顶层视图关联触摸事件的监听器
        mTouchText.setOnTouchListener(this);

    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        //如果需要的话,可以修改事件位置
        //这里我们将每个事件的垂直方向的位置设置为HorizonScrollView的中间
        event.setLocation(event.getX(),mScrollView.getHeight()/2);

        //将TextView上的每个事件转发到HorizontalScrollView
        mScrollView.dispatchTouchEvent(event);
        return true;
    }
}
